package com.browsesoft.adapter;

import java.util.LinkedList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.w3c.dom.Element;

import com.browsesoft.ExtendElement;
import com.browsesoft.user.User;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Copyright: Copyright (c) 2004
 * </p>
 * <p>
 * Company:
 * </p>
 * 
 * @author not attributable
 * @version 1.0
 */

public class UserAdapter extends User {
	/**
	 * 
	 */
	private static final long serialVersionUID = 6149583530892851101L;

	public UserAdapter() {
	}

	public void service(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		super.service(request, response);
		String t = request.getParameter("templatename");
		// 设置IP地址
		String IP = request.getServerName() + ":" + request.getServerPort();
		if (t != null && !t.equals("")) {
			Element element = this.getComponent().getElement();
			LinkedList ekeyObject = ExtendElement.findElements(element, "id",
					"BSEkey");
			if (ekeyObject.size() == 0) {
				// throw new RuntimeException("找不到必须的元素，id='BSEkey'");
				System.out.println("找不到必须的元素，id='BSEkey'");
				return;
			}
			Element obj = (Element) ekeyObject.get(0);
			// 设置codebase属性
			String codebase = obj.getAttribute("codebase");
			codebase = codebase.replaceAll("http:///", "http://" + IP + "/");
			obj.setAttribute("codebase", codebase);
		}

	}

}